// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-6-11

#ifndef __TINYXML_H_COMMON_BASE__
#define __TINYXML_H_COMMON_BASE__

#pragma once

class CJoyXmlAttribute;
class CJoyXmlElement;
//##ModelId=44CF175600EC
typedef CList<CJoyXmlAttribute*> CJoyXmlAttributeList;
//##ModelId=44CF175600EE
typedef CList<CJoyXmlElement*> CJoyXmlElementList;

//##ModelId=44CF175600FA
class CJoyXmlAttribute
{
public:
	//##ModelId=44CF175600FB
    CString m_name;
	//##ModelId=44CF175600FC
    CString m_value;
public:
	//##ModelId=44CF175600FD
    CJoyXmlAttribute()
    {
    }
	//##ModelId=44CF175600FE
    CJoyXmlAttribute(const CString& strName, const CString& strValue):
        m_name(strName), m_value(strValue)
    {
    }
};


//##ModelId=44CF1756010A
class CJoyXmlElement
{
protected:
	//##ModelId=44CF17560119
    CJoyXmlElement& operator = (const CJoyXmlElement& elem);

public:
	//##ModelId=44CF1756011B
    CString m_name;
	//##ModelId=44CF1756011C
    CString m_content;
	//##ModelId=44CF17560139
    CJoyXmlAttributeList    m_attributes;
	//##ModelId=44CF1756013E
    CJoyXmlElementList      m_elements;


public:
	//##ModelId=44CF17560142
    CJoyXmlElement()
    {
    }
	//##ModelId=44CF17560143
    CJoyXmlElement(const CString& strName):
        m_name(strName)
    {
    }
	//##ModelId=44CF17560149
    ~CJoyXmlElement();

	//##ModelId=44CF1756014A
    CJoyXmlAttribute* FindAttribute(PCSTR pszName);
	//##ModelId=44CF1756014C
    CJoyXmlAttribute* GetAttribute(PCSTR pszName, PCSTR pszValue = "");
	//##ModelId=44CF17560158
    CJoyXmlElement* FindElement(PCSTR pszName);
	//##ModelId=44CF1756015A
    CJoyXmlElement* GetElement(PCSTR pszName);

	//##ModelId=44CF1756015C
    bool FindRect(PCSTR attrib, CRect& rect);
	//##ModelId=44CF17560169
    CRect GetRect(PCSTR attrib, const CRect& def);

	//##ModelId=44CF1756016C
    bool ReadBoolean(PCSTR attrib, bool def = false);
	//##ModelId=44CF17560178
    int ReadIntD(PCSTR attrib, int def = 0);
	//##ModelId=44CF1756017B
    UINT ReadIntX(PCSTR attrib, UINT def = 0);
	//##ModelId=44CF17560186
    float ReadFloat(PCSTR attrib, float def = 0);
	//##ModelId=44CF17560189
    CString ReadString(PCSTR attrib, PCSTR pszDef = "");

	//##ModelId=44CF17560196
    void Save(CFile& f, const CString& strWhite);
};

//##ModelId=44CF17560199
class CJoyXmlFile
{
protected:
	//##ModelId=44CF175601A6
    CJoyXmlElement* m_root;
	//##ModelId=44CF175601AA
    CString m_fileName;
public:
	//##ModelId=44CF175601AB
    bool    m_encrypt;
public:
	//##ModelId=44CF175601B5
    CJoyXmlFile();
	//##ModelId=44CF175601B6
    ~CJoyXmlFile();

	//##ModelId=44CF175601B7
    CJoyXmlElement* GetRoot() const
    {
        return m_root;
    }

	//##ModelId=44CF175601B9
    void OpenXml(PCSTR pszXml, size_t nSize = (size_t)(-1));

	//##ModelId=44CF175601BC
    void Open(PCSTR pszFile = NULL, PCSTR pszDefRoot = "root");
	//##ModelId=44CF175601C5
    void Save(PCSTR pszFile = NULL);

};

CJoyXmlElement* JoyXmlParse(PCSTR pszSource, size_t nSize = (size_t)(-1));

#endif  // __TINYXML_H_COMMON_BASE__
